/* 
泛型约束
*/
(() => {

  interface LengthWise {
    length: number
  }
 
  // 可以将泛型理解为一种特殊的接口
  function getLength<T extends LengthWise>(value: T) {
    return value.length
  }

  class A {
    length: number
    constructor (length) {
      this.length = length
    }
  }

  console.log(getLength<string>('abc'))
  console.log(getLength<A>(new A(3)))
  // console.log(getLength<number>(123))  // error

  
})()